home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / frasr182.zip / CALMANFP.ASM < prev    next >
Assembly Source File  |  1992-02-26  |  43KB  |  1,125 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; calmanfp.asm - floating point version of the calcmand.asm file
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4. ; The following code was adapted from a little program called "Mandelbrot
  5. ; Sets by Wesley Loewer" which had a very limited distribution (my
  6. ; Algebra II class).  It didn't have any of the fancy integer math, but it
  7. ; did run floating point stuff pretty fast.
  8. ;
  9. ; The code was originally optimized for a 287 ('cuz that's what I've got)
  10. ; and for a large maxit (ie: use of generous overhead outside the loop to get
  11. ; slightly faster code inside the loop), which is generally the case when
  12. ; Fractint chooses to use floating point math.  This code also has the
  13. ; advantage that once the initial parameters are loaded into the fpu
  14. ; register, no transfers of fp values to/from memory are needed except to
  15. ; check periodicity and to show orbits and the like.  Thus, values keep all
  16. ; the significant digits of the full 10 byte real number format internal to
  17. ; the fpu.  Intermediate results are not rounded to the normal IEEE 8 byte
  18. ; format (double) at any time.
  19. ;
  20. ; The non fpu specific stuff, such as periodicity checking and orbits,
  21. ; was adapted from CALCFRAC.C and CALCMAND.ASM.
  22. ;
  23. ; This file must be assembled with floating point emulation turned on.  I
  24. ; suppose there could be some compiler differences in the emulation
  25. ; libraries, but this code has been successfully tested with the MSQC 2.51
  26. ; and MSC 5.1 emulation libraries.
  27. ;
  28. ;                                               Wes Loewer
  29. ;
  30. ; and now for some REAL fractal calculations...
  31. ; (get it, real, floating point..., never mind)
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  33.  
  34. ;                        required for compatibility if Turbo ASM
  35. IFDEF ??version
  36. MASM51
  37. QUIRKS
  38. ENDIF
  39.  
  40. .8086
  41. .8087
  42.  
  43. .MODEL medium,c
  44.  
  45. ; external functions
  46. EXTRN   keypressed:FAR          ; this routine is in 'general.asm'
  47. EXTRN   getakey:FAR             ; this routine is in 'general.asm'
  48. EXTRN   plot_orbit:FAR          ; this routine is in 'fracsubr.c'
  49. EXTRN   scrub_orbit:FAR         ; this routine is in 'fracsubr.c'
  50.  
  51. ; external data
  52. EXTRN init:WORD                 ; declared as type complex
  53. EXTRN parm:WORD                 ; declared as type complex
  54. EXTRN new:WORD                  ; declared as type complex
  55. EXTRN maxit:WORD
  56. EXTRN inside:WORD
  57. EXTRN outside:WORD
  58. EXTRN fpu:WORD                  ; fpu type: 87, 287, or 387
  59. EXTRN rqlim:QWORD               ; bailout (I never did figure out
  60.                 ;   what "rqlim" stands for. -Wes)
  61. EXTRN color:WORD
  62. EXTRN oldcolor:WORD
  63. EXTRN realcolor:WORD
  64. EXTRN periodicitycheck:WORD
  65. EXTRN reset_periodicity:WORD
  66. EXTRN closenuff:QWORD
  67. EXTRN fractype:WORD             ; Mandelbrot or Julia
  68. EXTRN kbdcount:WORD             ; keyboard counter
  69. EXTRN dotmode:WORD
  70. EXTRN show_orbit:WORD           ; "show-orbit" flag
  71. EXTRN orbit_ptr:WORD            ; "orbit pointer" flag
  72. EXTRN potflag:WORD              ; potential flag
  73. EXTRN magnitude:QWORD           ; when using potential
  74.  
  75. JULIAFP  EQU 6                  ; from FRACTYPE.H
  76. MANDELFP EQU 4
  77. GREEN    EQU 2                  ; near y-axis
  78. YELLOW   EQU 6                  ; near x-axis
  79.  
  80. initx    EQU <qword ptr init>   ; just to make life easier
  81. inity    EQU <qword ptr init+8>
  82. parmx    EQU <qword ptr parm>
  83. parmy    EQU <qword ptr parm+8>
  84. newx     EQU <qword ptr new>
  85. newy     EQU <qword ptr new+8>
  86.  
  87. ; Apparently, these might be needed for TC++ overlays. I don't know if
  88. ; these are really needed here since I am not familiar with TC++. -Wes
  89. FRAME   MACRO regs
  90.     push    bp
  91.     mov     bp, sp
  92.     IRP     reg, <regs>
  93.       push  reg
  94.       ENDM
  95.     ENDM
  96.  
  97. UNFRAME MACRO regs
  98.     IRP     reg, <regs>
  99.       pop reg
  100.       ENDM
  101.     pop bp
  102.     ENDM
  103.  
  104.  
  105. .DATA
  106.     align   2
  107. savedx                  DQ  ?
  108. savedy                  DQ  ?
  109. orbit_real              DQ  ?
  110. orbit_imag              DQ  ?
  111. close                   DD  0.01
  112. round_down_half         DD  0.5
  113. tmp_word                DW  ?
  114. inside_color            DW  ?
  115. periodicity_color       DW  ?
  116. ;savedand               DW  ?
  117. ;savedincr              DW  ?
  118. savedand                EQU     SI      ; this doesn't save much time or
  119. savedincr               EQU     DI      ; space, but it doesn't hurt either
  120.  
  121. .CODE
  122.  
  123. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  124. ; This routine is called once per image.
  125. ; Put things here that won't change from one pixel to the next.
  126. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  127. PUBLIC calcmandfpasmstart
  128. calcmandfpasmstart   PROC
  129.                     ; not sure if needed here
  130.     FRAME   <di,si>                 ; std frame, for TC++ overlays
  131.  
  132.     mov     ax,inside
  133.     cmp     ax,0                    ; if (inside color == maxiter)
  134.     jnl     non_neg_inside
  135.     mov     ax,maxit                ;   use maxit as inside_color
  136.  
  137. non_neg_inside:                         ; else
  138.     mov     inside_color,ax         ;   use inside as inside_color
  139.  
  140.     cmp     periodicitycheck,0      ; if periodicitycheck < 0
  141.     jnl     non_neg_periodicitycheck
  142.     mov     ax,7                    ;   use color 7 (default white)
  143. non_neg_periodicitycheck:               ; else
  144.     mov     periodicity_color,ax    ;   use inside_color still in ax
  145.     mov     oldcolor,0              ; no periodicity checking on 1st pixel
  146.     sub     ax,ax                   ; ax=0
  147.     UNFRAME <si,di>                 ; pop stack frame
  148.     ret
  149. calcmandfpasmstart       ENDP
  150.  
  151. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  152. ; floating point version of calcmandasm
  153. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  154. PUBLIC calcmandfpasm
  155. calcmandfpasm  PROC
  156.     FRAME   <di,si>                 ; std frame, for TC++ overlays
  157. ; initialization stuff
  158.     sub     ax,ax                   ; clear ax
  159.     cmp     periodicitycheck,ax     ; periodicity checking?
  160.     je      initoldcolor            ;  no, set oldcolor 0 to disable it
  161.     cmp     inside,-59              ; zmag?
  162.     je      initoldcolor            ;  set oldcolor to 0
  163.     cmp     reset_periodicity,ax    ; periodicity reset?
  164.     je      short initparms         ;  no, inherit oldcolor from prior invocation
  165.     mov     ax,maxit                ; yup.  reset oldcolor to maxit-250
  166.     sub     ax,250                  ; (avoids slowness at high maxits)
  167. initoldcolor:
  168.     mov     oldcolor,ax             ; reset oldcolor
  169.  
  170. initparms:
  171.     sub     ax,ax                   ; clear ax
  172.     mov     word ptr savedx,ax      ; savedx = 0.0
  173.     mov     word ptr savedx+2,ax    ; needed since savedx is a QWORD
  174.     mov     word ptr savedx+4,ax
  175.     mov     word ptr savedx+6,ax
  176.     mov     word ptr savedy,ax      ; savedy = 0.0
  177.     mov     word ptr savedy+2,ax    ; needed since savedy is a QWORD
  178.     mov     word ptr savedy+4,ax
  179.     mov     word ptr savedy+6,ax
  180.     inc     ax                      ; ax = 1
  181.     mov     savedand,ax             ; savedand = 1
  182.     mov     savedincr,ax            ; savedincr = 1
  183.     mov     orbit_ptr,0             ; clear orbits
  184.     dec     kbdcount                ; decrement the keyboard counter
  185.     jns     short nokey             ;  skip keyboard test if still positive
  186.     mov     kbdcount,10             ; stuff in a low kbd count
  187.     cmp     show_orbit,0            ; are we showing orbits?
  188.     jne     quickkbd                ;  yup.  leave it that way.
  189. ;this may need to be adjusted, I'm guessing at the "appropriate" values -Wes
  190.     mov     kbdcount,5000           ; else, stuff an appropriate count val
  191.     cmp     fpu,387                 ; ("appropriate" to the FPU)
  192.     je      short kbddiskadj        ;     ...
  193.     mov     kbdcount,3000           ;     ...
  194.     cmp     fpu,287                 ;     ...
  195.     je      short kbddiskadj        ;     ...
  196.     mov     kbdcount,1000           ;     ...
  197.     cmp     fpu,87                  ;     ...
  198.     je      short kbddiskadj        ;     ...
  199.     mov     kbdcount,500            ; emulation
  200. kbddiskadj:
  201.     cmp     dotmode,11              ; disk video?
  202.     jne     quickkbd                ;  no, leave as is
  203.     mov     cl,2                    ; yes, reduce count
  204.     shr     kbdcount,cl             ;  ..